type A = {
    username:string,
    age:number
}

let a:A = {
    username:'xiaoming',
    age:20
}

type B = {
    username:string,
    //可选
    age?:number
}

let b:B = {
    username:'xiaoming',
}


type C = {
    username:string,
    //可选
    age?:number
    //索引签名 其他属性key为string，值任何类型
    [index:string]:any
}

let c:C = {
    username:'xiaoming',
    age:20,
    sex:'男',
    height:180
}

type D = {
    [index:string] :any
}

let d:D = {
    username:'xiaoming',
    age:20,
    sex:'男',
    height:180
}

//数组建议用
type E = {
    [index:number] :any
}

let d1:E = [1,2,3,4,'hello' , true]

//编译error
//let obj1: {username:string} = {};

//需用断言
type Obj = {
    username:string
}

let obj = {} as Obj;

//数组内子项必须符合json指定的字段
let json:{username:string ,age:number}[] = [{
    username:'xiaoming',
    age:20
}];

console.log(json)